home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / macpath.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  8KB  |  260 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Pathname and path-related operations for the Macintosh.'''
  5. import os
  6. import warnings
  7. from stat import *
  8. import genericpath
  9. from genericpath import *
  10. __all__ = [
  11.     'normcase',
  12.     'isabs',
  13.     'join',
  14.     'splitdrive',
  15.     'split',
  16.     'splitext',
  17.     'basename',
  18.     'dirname',
  19.     'commonprefix',
  20.     'getsize',
  21.     'getmtime',
  22.     'getatime',
  23.     'getctime',
  24.     'islink',
  25.     'exists',
  26.     'lexists',
  27.     'isdir',
  28.     'isfile',
  29.     'walk',
  30.     'expanduser',
  31.     'expandvars',
  32.     'normpath',
  33.     'abspath',
  34.     'curdir',
  35.     'pardir',
  36.     'sep',
  37.     'pathsep',
  38.     'defpath',
  39.     'altsep',
  40.     'extsep',
  41.     'devnull',
  42.     'realpath',
  43.     'supports_unicode_filenames']
  44. curdir = ':'
  45. pardir = '::'
  46. extsep = '.'
  47. sep = ':'
  48. pathsep = '\n'
  49. defpath = ':'
  50. altsep = None
  51. devnull = 'Dev:Null'
  52.  
  53. def normcase(path):
  54.     return path.lower()
  55.  
  56.  
  57. def isabs(s):
  58.     '''Return true if a path is absolute.
  59.     On the Mac, relative paths begin with a colon,
  60.     but as a special case, paths with no colons at all are also relative.
  61.     Anything else is absolute (the string up to the first colon is the
  62.     volume name).'''
  63.     if ':' in s:
  64.         pass
  65.     return s[0] != ':'
  66.  
  67.  
  68. def join(s, *p):
  69.     path = s
  70.     for t in p:
  71.         if not s or isabs(t):
  72.             path = t
  73.             continue
  74.         
  75.         if t[:1] == ':':
  76.             t = t[1:]
  77.         
  78.         if ':' not in path:
  79.             path = ':' + path
  80.         
  81.         if path[-1:] != ':':
  82.             path = path + ':'
  83.         
  84.         path = path + t
  85.     
  86.     return path
  87.  
  88.  
  89. def split(s):
  90.     '''Split a pathname into two parts: the directory leading up to the final
  91.     bit, and the basename (the filename, without colons, in that directory).
  92.     The result (s, t) is such that join(s, t) yields the original argument.'''
  93.     if ':' not in s:
  94.         return ('', s)
  95.     colon = 0
  96.     for i in range(len(s)):
  97.         if s[i] == ':':
  98.             colon = i + 1
  99.             continue
  100.         ':' not in s
  101.     
  102.     path = s[:colon - 1]
  103.     file = s[colon:]
  104.     if path and ':' not in path:
  105.         path = path + ':'
  106.     
  107.     return (path, file)
  108.  
  109.  
  110. def splitext(p):
  111.     return genericpath._splitext(p, sep, altsep, extsep)
  112.  
  113. splitext.__doc__ = genericpath._splitext.__doc__
  114.  
  115. def splitdrive(p):
  116.     """Split a pathname into a drive specification and the rest of the
  117.     path.  Useful on DOS/Windows/NT; on the Mac, the drive is always
  118.     empty (don't use the volume name -- it doesn't have the same
  119.     syntactic and semantic oddities as DOS drive letters, such as there
  120.     being a separate current directory per drive)."""
  121.     return ('', p)
  122.  
  123.  
  124. def dirname(s):
  125.     return split(s)[0]
  126.  
  127.  
  128. def basename(s):
  129.     return split(s)[1]
  130.  
  131.  
  132. def ismount(s):
  133.     if not isabs(s):
  134.         return False
  135.     components = split(s)
  136.     if len(components) == 2:
  137.         pass
  138.     return components[1] == ''
  139.  
  140.  
  141. def islink(s):
  142.     '''Return true if the pathname refers to a symbolic link.'''
  143.     
  144.     try:
  145.         import Carbon.File as Carbon
  146.         return Carbon.File.ResolveAliasFile(s, 0)[2]
  147.     except:
  148.         return False
  149.  
  150.  
  151.  
  152. def lexists(path):
  153.     '''Test whether a path exists.  Returns True for broken symbolic links'''
  154.     
  155.     try:
  156.         st = os.lstat(path)
  157.     except os.error:
  158.         return False
  159.  
  160.     return True
  161.  
  162.  
  163. def expandvars(path):
  164.     '''Dummy to retain interface-compatibility with other operating systems.'''
  165.     return path
  166.  
  167.  
  168. def expanduser(path):
  169.     '''Dummy to retain interface-compatibility with other operating systems.'''
  170.     return path
  171.  
  172.  
  173. class norm_error(Exception):
  174.     '''Path cannot be normalized'''
  175.     pass
  176.  
  177.  
  178. def normpath(s):
  179.     '''Normalize a pathname.  Will return the same result for
  180.     equivalent paths.'''
  181.     if ':' not in s:
  182.         return ':' + s
  183.     comps = s.split(':')
  184.     i = 1
  185.     while i < len(comps) - 1:
  186.         if comps[i] == '' and comps[i - 1] != '':
  187.             if i > 1:
  188.                 del comps[i - 1:i + 1]
  189.                 i = i - 1
  190.             else:
  191.                 raise norm_error, 'Cannot use :: immediately after volume name'
  192.         i > 1
  193.         i = i + 1
  194.         continue
  195.         ':' not in s
  196.     s = ':'.join(comps)
  197.     if s[-1] == ':' and len(comps) > 2 and s != ':' * len(s):
  198.         s = s[:-1]
  199.     
  200.     return s
  201.  
  202.  
  203. def walk(top, func, arg):
  204.     """Directory tree walk with callback function.
  205.  
  206.     For each directory in the directory tree rooted at top (including top
  207.     itself, but excluding '.' and '..'), call func(arg, dirname, fnames).
  208.     dirname is the name of the directory, and fnames a list of the names of
  209.     the files and subdirectories in dirname (excluding '.' and '..').  func
  210.     may modify the fnames list in-place (e.g. via del or slice assignment),
  211.     and walk will only recurse into the subdirectories whose names remain in
  212.     fnames; this can be used to implement a filter, or to impose a specific
  213.     order of visiting.  No semantics are defined for, or required of, arg,
  214.     beyond that arg is always passed to func.  It can be used, e.g., to pass
  215.     a filename pattern, or a mutable object designed to accumulate
  216.     statistics.  Passing None for arg is common."""
  217.     warnings.warnpy3k('In 3.x, os.path.walk is removed in favor of os.walk.', stacklevel = 2)
  218.     
  219.     try:
  220.         names = os.listdir(top)
  221.     except os.error:
  222.         return None
  223.  
  224.     func(arg, top, names)
  225.     for name in names:
  226.         name = join(top, name)
  227.         if isdir(name) and not islink(name):
  228.             walk(name, func, arg)
  229.             continue
  230.     
  231.  
  232.  
  233. def abspath(path):
  234.     '''Return an absolute path.'''
  235.     if not isabs(path):
  236.         path = join(os.getcwd(), path)
  237.     
  238.     return normpath(path)
  239.  
  240.  
  241. def realpath(path):
  242.     path = abspath(path)
  243.     
  244.     try:
  245.         import Carbon.File as Carbon
  246.     except ImportError:
  247.         return path
  248.  
  249.     if not path:
  250.         return path
  251.     components = path.split(':')
  252.     path = components[0] + ':'
  253.     for c in components[1:]:
  254.         path = join(path, c)
  255.         path = Carbon.File.FSResolveAliasFile(path, 1)[0].as_pathname()
  256.     
  257.     return path
  258.  
  259. supports_unicode_filenames = False
  260.